var urlList = server_host + '/mainview/getOrderDetail.do';

var shopId = getParameterByName('shopId');
var shopTablePriceId = getParameterByName('shopTablePriceId');
var orderDate = getParameterByName('orderDate');

var appModule = angular.module('CheerHiWx', []);
appModule.controller('PackageCtrl', ['$scope', '$http', function($scope, $http) {

	$scope.shopInfo = base64TojsonObj(sessionStorage.getItem('shopInfo'));

	$scope.checkStatus = {
		startTime: 0,
		themeId: 0,
		tableId: 0,
		themeName: ''
	}

	$scope.loadList = function() {
		$http.get(urlList + '?shopId=' + shopId + '&shopTablePriceId=' + shopTablePriceId + '&orderDate=' + orderDate).success(function(data, status, headers, config) {
			console.log(data);
			$scope.packageDetails = data;
			$scope.checkStatus.startTime = data.startTimeList[0].time;
			if (data.themeList.length > 0) {
				// $scope.checkStatus.themeId = data.themeList[0].styleId;
				$scope.checkStatus.tableId = data.themeList[0].tableId;
				// $scope.checkStatus.themeName = data.themeList[0].themeName;
			}
		});
	};

	$scope.selectTime = function(date, time) {
		$scope.checkStatus.startTime = time;
		orderDate = date;
	}

	$scope.selectTheme = function(themeId, tableId, themeName) {
		if ($scope.checkStatus.themeId == 0 || $scope.checkStatus.themeId != themeId) {
			$scope.checkStatus.themeId = themeId;
			$scope.checkStatus.tableId = tableId;
			$scope.checkStatus.themeName = themeName;
		} else if ($scope.checkStatus.themeId == themeId) {
			$scope.checkStatus.themeId = 0;
			$scope.checkStatus.tableId = 0;
			$scope.checkStatus.themeName = '';
		}
	}

	$scope.commitOrder = function() {
		var cash = $scope.packageDetails.price;
		location.href = 'confirm-order.html?shopId=' + shopId + '&cash=' + cash + '&styleId=' + $scope.checkStatus.themeId + '&tableId=' + $scope.checkStatus.tableId + '&orderDate=' + orderDate + '&time=' + $scope.checkStatus.startTime + '&shopTablePriceId=' + shopTablePriceId + '&themeName=' + encodeURIComponent($scope.checkStatus.themeName);
	}

	$scope.loadList();
}]);